package com.pretty.test.controller.pets.baike;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pretty.test.controller.pets.baike.dto.BaikePageDTO;
import com.pretty.test.controller.pets.baike.vo.BaikeDashboardSimpleListVO;
import com.pretty.test.controller.pets.baike.vo.BaikeDashboardVO;
import com.pretty.test.controller.pets.baike.vo.BaikePageVO;
import com.pretty.test.entity.PetsBaike;
import com.pretty.test.service.IPetsBaikeService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 宠物百科控制器
 * @author dujianyu
 * @since 2021-04-06
 */
@RestController
@AllArgsConstructor
@RequestMapping("/baike")
public class PetsBaikeController {

    private IPetsBaikeService service;

    /**
     * 自定义分页
     * @param page
     * @param dto
     */
    @GetMapping("/page")
    public R<IPage<BaikePageVO>> page(Page<BaikePageVO> page, BaikePageDTO dto){
        return R.ok(service.selectBaikePage(page,dto));
    }

    /**
     * 首页列表数据
     */
    @GetMapping("/dashboardList")
    public R<List<BaikeDashboardVO>> dashboardList(){
        return R.ok(service.dashboardList());
    }

    /**
     * 首页简单列表数据
     */
    @GetMapping("/dashboardSimpleList")
    public R<List<BaikeDashboardSimpleListVO>> dashboardSimpleList(BaikePageDTO dto){
        return R.ok(service.dashboardSimpleList(dto));
    }

    /**
     * 新增或修改
     * @param petsBaike
     */
    @PostMapping("/submit")
    public  R<Boolean> submit(@RequestBody PetsBaike petsBaike){
        return R.ok(service.saveOrUpdate(petsBaike));
    }

    /**
     * 逻辑删除
     * @param id
     */
    @PostMapping("/delete")
    public R<Boolean> delete(String id){
        return R.ok(service.removeById(id));
    }

}
